<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>设置我的资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
</head>
<body>

<div class="layui-form" style="padding: 20px 0 0 0;">
    <div class="layui-form-item" style="display: none" th:if="${banner != null}">
        <label class="layui-form-label">ID</label>
        <div class="layui-input-inline">
            <input th:value="${banner.id}" type="text" name="id" id="id" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">广告地址</label>
        <div class="layui-input-inline">
            <input name="url" lay-verify="required" id="url" placeholder="广告地址"
                   th:value="${banner!=null}?${banner.url}"
                   class="layui-input">
        </div>
        <div class="layui-input-inline layui-btn-container" style="width: auto;">
            <button type="button" class="layui-btn layui-btn-primary" id="uploadUrl">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <button class="layui-btn layui-btn-primary" id="showUrl">查看图片
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-inline">
            <input type="text" name="desc" th:value="${banner!=null}?${banner.desc}" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否展示</label>
        <div class="layui-input-block" th:if="${banner == null || banner.ishow eq 1}">
            <input type="radio" name="ishow" value="1" title="展示" checked>
            <input type="radio" name="ishow" value="0" title="不展示">
        </div>
        <div class="layui-input-block" th:if="${banner != null && banner.ishow eq 0}">
            <input type="radio" name="ishow" value="1" title="展示">
            <input type="radio" name="ishow" value="0" title="不展示" checked>
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="addAdmin" id="addAdmin" value="确认">
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'layer', 'upload', 'form'], function () {
        var $ = layui.$,
            layer = layui.layer,
            form = layui.form,
            upload = layui.upload;

        $('#showSrc').on('click', function () {
            layer.photos(
                {photos: {title: "查看", data: [{src: $("#url").val()}]}, shade: .01, closeBtn: 1, anim: 5}
            )
            return false;
        });

        $('#showUrl').on('click', function () {
            layer.photos(
                {photos: {title: "查看", data: [{src: $("#url").val()}]}, shade: .01, closeBtn: 1, anim: 5}
            )
            return false;
        });

        var uploadSrc = upload.render({
            elem: '#uploadSrc' //绑定元素
            , url: '/upload' //上传接口
            , done: function (res) {
                //上传完毕回调
                if (res.code == 200) {
                    $("#src").val(res.msg);
                    layer.msg('图片上传成功',
                        {
                            icon: 1,
                            time: 800
                        });
                } else {
                    layer.msg('图片上传失败');
                }
            }
            , error: function () {
                //请求异常回调
            }
        });

        var uploadUrl = upload.render({
            elem: '#uploadUrl' //绑定元素
            , url: '/upload' //上传接口
            , done: function (res) {
                //上传完毕回调
                if (res.code == 200) {
                    $("#url").val(res.msg);
                    layer.msg('图片上传成功',
                        {
                            icon: 1,
                            time: 800
                        });
                } else {
                    layer.msg('图片上传失败');
                }
            }
            , error: function () {
                //请求异常回调
            }
        });
    });
</script>
</body>
</html>